package org.example.controller;

import org.example.sse.SSEServer;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
public class ConnectController {

    @CrossOrigin
    @GetMapping(path = "/sse/connect", produces = {MediaType.TEXT_EVENT_STREAM_VALUE})
    public SseEmitter connect(@RequestParam(name = "userId") String userId) {
        System.out.println("userId = " + userId);
        return SSEServer.connect(userId);
    }
}
